<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>

    const name = "The Window"

    const object = {
      name: "My Object",
      getNameFunc: function () {
        return function () {
          return this.name
        }
      }
    }
    // const object = {
    //   name: "My Object",
    //   getNameFunc: function () {
    //     const that = this
    //     return function () {
    //       return that.name
    //     }
    //   }
    // }

    console.log(object.getNameFunc()())

// this指向的形式4种:
// 1.如果是一般函数,this指向全局对象window;
// 2.在严格模式下"use strict",为undefined.
// 3.对象的方法里调用,this指向调用该方法的对象.
// 4.构造函数里的this,指向创建出来的实例.
  </script>
</body>

</html>